package br;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Servlet implementation class statystykim
 */
@WebServlet("/statystykim")
public class statystykim extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public statystykim() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession sesja = request.getSession(true);
		 response.setCharacterEncoding("UTF-8");
		 PrintWriter out = response.getWriter();
		 System.out.println(sesja.getAttribute("log")+"sesja");
		 if(sesja.getAttribute("log")!=null&&sesja.getAttribute("log").equals("kurier")){
				String log = (String)sesja.getAttribute("nick");
				String odp="";
				try {
				  Connection con =mb.commons.DbConnection.getConnection 
				  ();
				  Statement stmt = con.createStatement();
				  System.out.println(log+"login");
				  
				  ResultSet rs = stmt.executeQuery("SELECT * FROM uzytkownicy,kurierzy,kurierzy_kilometry WHERE login = '"+log+"' AND uzytkownicy.id=kurierzy.id AND kurierzy_kilometry.idkuriera=kurierzy.id_kuriera");
				  while(rs.next()){
					  odp+=""+rs.getDate("data")+" przejechano kilometrow: "+rs.getInt("ilosckm")+"&";
					 
							
				  
	}
				}catch(Exception e){
					e.printStackTrace();
		
	}
				  response.setContentType("text/html;charset=UTF-8");
				  	System.out.println(odp+"abc");
					out.println(odp);
					out.close();  
}
	}
}